package com.javabasic.algorithm.leetcode;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/2/3 10:31
 * @Version 1.0
 * @题解： https://leetcode-cn.com/problems/valid-sudoku/comments/
 **/
public class ValidSudoku {
    public boolean isValidSudoku(char[][] board) {
        int len = board.length;
        int k = 0;
        int[][] mapx = new int[9][10];
        int[][] mapy = new int[9][10];
        int[][][] map = new int[3][3][10];
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len; j++) {
                char ch = board[i][j];
                if (ch != '.' ) {
                    int num = ch - '0';
                    // x 便是纵向， y 是横向
                    int x = k / 9 / 3;
                    int y = k % 9 / 3;
                    System.out.println(num);
                    if (mapx[i][num] == 0 && mapy[num][j] == 0 && map[x][y][num] == 0) {
                        mapx[i][num] = 1;
                        mapy[num][j] = 1;
                        map[x][y][num] = 1;
                    } else {
                        System.out.println(i + " " + j + " " + num + " " + x + "-" + y);
                        return false;
                    }
                }
                k++;
            }
        }
        return true;
    }
}
